package csci5115.autoalarm;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class EventViewAdapter extends BaseAdapter {
	ArrayList<AAEvent> mEvents;
	Context mContext;

	public EventViewAdapter(Context context, ArrayList<AAEvent> events) {
		mContext = context;
		mEvents = events;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		if (mEvents != null) {
			return mEvents.size();
		} else {
			return 0;
		}
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mEvents.get(arg0);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int arg0, View arg1, ViewGroup parent) {

		RelativeLayout rl = new RelativeLayout(mContext);
		TextView title = new TextView(mContext);
		title.setText(mEvents.get(arg0).getTitle());
		RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.WRAP_CONTENT,
				RelativeLayout.LayoutParams.WRAP_CONTENT);
		params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
		params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		title.setTextSize(20);
		title.setLayoutParams(params);
		title.setId(1);
		rl.addView(title);
		
		RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.WRAP_CONTENT,
				RelativeLayout.LayoutParams.WRAP_CONTENT);
		params2.addRule(RelativeLayout.BELOW, 1);
		TextView date = new TextView(mContext);
		date.setText(mEvents.get(arg0).getTime());
		date.setLayoutParams(params2);
		rl.addView(date); 
		return rl;
	}

}
